<template>
<div>
    <div class="login_bg">
        <div class="login_container">
            <img class="svg" src="../../static/img/u9.svg" />
            <h1>EMP平台登录</h1>
            <h3>EMP platform login</h3>
            <input type="text" onkeypress="javascript:if(event.keyCode == 32)event.returnValue=false" placeholder=" 请输入账号" v-model="loginForm.username" @keyup.enter="handleAddBook" />
            <input type="password" onkeypress="javascript:if(event.keyCode == 32)event.returnValue=false" placeholder=" 请输入密码" v-model="loginForm.password" @keyup.enter="handleAddBook" />
            <button @click="login">登录</button>
            <div v-show="isShow">请填写正确的用户名/密码</div>
        </div>
    </div>
</div>
</template>

<script>
export default {
    data() {
        return {
            isShow: false,
            text: '',
            loginForm: {
                username: '',
                password: '',
            },
            userInfo: [],
            value: '',
        }
    },
    created() {
        window.sessionStorage.setItem('currentIndex', 0);
        this.keyupEnter()
    },
    methods: {
        keyupEnter() {
            document.onkeydown = (e) => {
                let body = document.getElementsByTagName('body')[0]
                if (e.keyCode === 13 && e.target.baseURI.match(/Login/) && e.target === body) {
                    this.handleAddBook()
                }
            }
        },
        handleAddBook() {
            this.login()
        },
        login() {
            event.stopPropagation()
            // const date = new Date()
            // this.$router.push('/pic')
            if (this.loginForm.username.trim() === '') {
                this.$message.error('请输入帐号')
                return false
            }
            if (this.loginForm.password.trim() === '') {
                this.$message.error('请输入密码')
                return false
            }

            this.value = true

            this.$axios
                .post('login/auth', {
                    username: this.loginForm.username,
                    password: this.loginForm.password
                })
                .then((res) => {
                    if (res.data.code == 2) {
                        this.userInfo = res.data.data;
                        // window.sessionStorage.setItem('userinfo', JSON.stringify(res.data.data.name))
                        // window.sessionStorage.setItem(
                        //     'token',
                        //     JSON.stringify(res.data.data.token)
                        // )
                        window.localStorage['userinfo'] = JSON.stringify(res.data.data.name);
                        window.localStorage['token'] = JSON.stringify(res.data.data.token);
                        window.localStorage['startTime'] = (new Date()).getTime();
                        // console.log(res.data);
                        this.$router.push('/shebeiDT');
                    } else {
                        this.$message.error('用户名或密码错误！')
                        this.value = false
                    }
                })
                .catch((err) => {
                    this.$message.error('登录失败！')
                })

        },
        onSuccess(times) {

        },
    },
}
</script>

<style scoped>
.login_container>div {
    width: 242px;
    height: 30px;
    color: rgb(252, 5, 5);
    text-align: left;
    line-height: 30px;
    font-family: 'FontAwesome';
    font-weight: 400;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 520px;
    border-radius: 5px;
    padding-left: 40px;
    background: url(../../static/img/err.png) no-repeat;
    background-size: 20px;
    background-position: 10px;
}

input:hover {
    cursor: pointer;
}

input::-webkit-input-placeholder {
    color: rgba(173, 173, 173, 0.6);
    font-size: 16px;
}

.login_container>button:hover {
    cursor: pointer;
}

.login_container>button {
    width: 280px;
    height: 45px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background-color: #0079FE;
    color: #fff;
    font-size: 20px;
    margin-top: 460px;
    border-radius: 8px;
    border: none;
}

.login_container>input {
    width: 300px;
    height: 50px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    border: 0.5px solid #8d8b8b;
    border-radius: 6px;
    padding-left: 40px;
    padding-left: 45px;
    outline: none;
}

.login_container>input:nth-of-type(1) {
    margin-top: 296px;
    background: url(../../static/img/shouji.png) no-repeat;
    background-size: 32px 32px;
    background-position: 6px;
}

.login_container>input:nth-of-type(2) {
    margin-top: 372px;
    background: url(../../static/img/mima.png) no-repeat;
    background-size: 32px 32px;
    background-position: 6px;
}

.login_container>h1 {
    font-size: 26px;
    font-family: '微软雅黑 Bold', '微软雅黑';
    font-weight: 700;
    color: #0079FE;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 200px;
}

.login_container>h3 {
    font-size: 20px;
    font-family: '微软雅黑 Bold', '微软雅黑';
    font-weight: 400;
    color: #0079FE;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 234px;
}

.svg {
    border-width: 0px;
    position: absolute;
    left: 0px;
    top: 0px;
    width: 115px;
    height: 115px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 60px;
}

.login_bg {
    width: 100vw;
    height: 100vh;
    background: url(../../static/img/u0_state0.png) no-repeat rgba(0, 121, 254, 1);
    background-size: 100% 100%;
    position: relative;
}

.login_container {
    width: 420px;
    height: 580px;
    background-color: rgba(255, 255, 255, 1);
    border-radius: 20px;
    box-shadow: 0px 0px 10px rgb(0 0 0 / 35%);
    font-family: '微软雅黑 Bold', '微软雅黑';
    font-weight: 700;
    font-size: 16px;
    color: #999999;
    line-height: 20px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
</style>
